package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要用到的数据
 */
public class OrderConfirmVo {
    //收货地址 ums_member_receive_address表
    @Getter
    @Setter
    List<MemberAddressVo> addressVos;

    //所有选中的购物项
    @Getter
    @Setter
    List<OrderItemVo> itemVos;

    //发票信息.....
    //优惠券信息
    @Getter
    @Setter
    Integer integration;

    @Getter
    @Setter
    Map<Long,Boolean> stocks;
    //订单总额 进行计算
//    BigDecimal total;
    //应付价格
//    BigDecimal payPrice;

    //防重令牌
    @Getter
    @Setter
    String orderToken;

    public  Integer getCount(){
        Integer i = 0;
        if (itemVos != null) {
            for (OrderItemVo itemVo : itemVos) {
               i += itemVo.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (itemVos != null) {
            for (OrderItemVo itemVo : itemVos) {
                BigDecimal multiply = itemVo.getPrice().multiply(new BigDecimal(itemVo.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }


    public BigDecimal getPayPrice() {
        return getTotal();
    }


}
